package day10.FileTest;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Homework {
    public static void main(String[] args) {
        File dir = new File("/Users/hao/Desktop/sdf");
        if(!dir.isDirectory()){
            System.out.println("不是目录!");
            return;
        }
        List<File> files= findDirPicture(dir);
        for(File f: files){
            System.out.println(f.getAbsolutePath());
        }
    }

    private static List<File> findDirPicture(File dir) {
        List<File> list = new ArrayList<>();
        findpic(dir, list);
        return list;
    }

    private static void findpic(File dir, List<File> list) {
        File[] files = dir.listFiles();
        if(files == null){
            return;
        }
        for (File f: files) {
            if(f.isFile()){
                if(f.getName().toLowerCase().matches(".+\\.(jpg|gif|png|bmp)")){
                    list.add(f);
                }
            }else{
                findpic(f, list);
            }

        }
    }

}
